Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

provider-panel.tsx 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from 'classnames'
  6. import { TracingProvider } from './type'
  7. import { LangfuseIconBig, LangsmithIconBig } from '@/app/components/base/icons/src/public/tracing'
  8. import { Settings04 } from '@/app/components/base/icons/src/vender/line/general'
  9. const I18N_PREFIX = 'app.tracing'
  10. type Props = {
  11. type: TracingProvider
  12. readOnly: boolean
  13. isChosen: boolean
  14. onChoose: () => void
  15. hasConfigured: boolean
  16. onConfig: () => void
  17. }
  18. const getIcon = (type: TracingProvider) => {
  19. return ({
  20. [TracingProvider.langSmith]: LangsmithIconBig,
  21. [TracingProvider.langfuse]: LangfuseIconBig,
  22. })[type]
  23. }
  24. const ProviderPanel: FC<Props> = ({
  25. type,
  26. readOnly,
  27. isChosen,
  28. onChoose,
  29. hasConfigured,
  30. onConfig,
  31. }) => {
  32. const { t } = useTranslation()
  33. const Icon = getIcon(type)
  34. const handleConfigBtnClick = useCallback((e: React.MouseEvent) => {
  35. e.stopPropagation()
  36. onConfig()
  37. }, [onConfig])
  38. const handleChosen = useCallback((e: React.MouseEvent) => {
  39. e.stopPropagation()
  40. if (isChosen || !hasConfigured || readOnly)
  41. return
  42. onChoose()
  43. }, [hasConfigured, isChosen, onChoose, readOnly])
  44. return (
  45. <div
  46. className={cn(isChosen ? 'border-primary-400' : 'border-transparent', !isChosen && hasConfigured && !readOnly && 'cursor-pointer', 'px-4 py-3 rounded-xl border-[1.5px] bg-gray-100')}
  47. onClick={handleChosen}
  48. >
  49. <div className={'flex justify-between items-center space-x-1'}>
  50. <div className='flex items-center'>
  51. <Icon className='h-6' />
  52. {isChosen && <div className='ml-1 flex items-center h-4 px-1 rounded-[4px] border border-primary-500 leading-4 text-xs font-medium text-primary-500 uppercase '>{t(`${I18N_PREFIX}.inUse`)}</div>}
  53. </div>
  54. {!readOnly && (
  55. <div
  56. className='flex px-2 items-center h-6 bg-white rounded-md border-[0.5px] border-gray-200 shadow-xs cursor-pointer text-gray-700 space-x-1'
  57. onClick={handleConfigBtnClick}
  58. >
  59. <Settings04 className='w-3 h-3' />
  60. <div className='text-xs font-medium'>{t(`${I18N_PREFIX}.config`)}</div>
  61. </div>
  62. )}
  63. </div>
  64. <div className='mt-2 leading-4 text-xs font-normal text-gray-500'>
  65. {t(`${I18N_PREFIX}.${type}.description`)}
  66. </div>
  67. </div>
  68. )
  69. }
  70. export default React.memo(ProviderPanel)